package com.hoperun.product.net;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.hoperun.product.common.Setting;

public class IServiceImpl {

    public static final String TAG = "IServiceImpl";

    public static final int LOGIN_R = 0;


    public static final int GET_TRAY_BY_TRAYNO = 1;

    public static final int GET_TRAY_BY_TKTNO = 2;

    public static final int GET_CONTACT_BY_TKTNO = 3;

    public static final int CHECK_CLOTHTKTNO = 4;

    public static final int CHECK_CLOTHTKTNO_BY_DETAIL = 5;

    public static final int ADD_CLOTH = 6;

    public static final int DELETE_CLOTH = 7;

    public static final int FINISH_UPDATE = 8;

    public static final int GET_INIT_INFO = 9;
    public static final int INSERT_MONTH = 10;
    public static final int GET_NEW_VERSION = 11;

    public static final int storehouseJudge = 12;
    public static final int inboundConfirm = 13;
    public static final int getStockData=14;
    public static final int outboundConfirm= 15 ;
    public static final int getReturnboundData=16;
    public static final int returnboundConfirm=17;
    public static final int unlockWhloc=18;
    public static final int GET_WJGTRAY_BY_TRAYNO = 19;
    public static final int CHECK_WJGCLOTHTKTNO = 20;
    public static final int ADD_WJGCLOTH = 21;
    public static final int FINISH_WJGUPDATE = 22;

    public static void callWebMethod(final Handler mHandler,
                                     final int requestType, final Object inputInfo, final String methodName) {
        new Thread() {
            @Override
            public void run() {


                String jsonStr = WebServiceAccessUtils.call(methodName, inputInfo.toString());

                Message msg = Message.obtain();
                msg.what = requestType;
                msg.arg1 = 1;
                try {
                    JSONObject json = new JSONObject(jsonStr);
                    String falg = json.optString(Setting.OPT_FLAG);
                    String info = json.optString(Setting.MSG_INFO);
                    if (falg.equals("0")) {
                        msg.arg1 = 0;
                    } else {
                        msg.arg1 = 1;
                    }
                    if (info != null) {
                        msg.obj = info;
                    }
                } catch (JSONException e) {
                    msg.arg1 = 1;
                    msg.obj = e.toString();
                }
                mHandler.sendMessage(msg);
            }
        }.start();
    }


}
